import { symbolMatch } from '@/utils/symbolMatch'
import { curryRight } from 'lodash'
// 提成配置Columns
const exchangeSymbol = (val) => {
  if (val === '1') {
    return symbolMatch('3')
  } else {
    return symbolMatch('4')
  }
}
export const configColumns = ctx => {
  return [
    {
      label: '档位',
      render: (h, row, index) => {
        return <span>档位 {index + 1}</span>
      }
    },
    {
      label: '销售单价(元/张)',
      render: (h, row) => {
        return [
          <span v-show={+row.sectionType === 1}>
            {/* 符号取相反，只为了展示用 */}
            {row.minValue}元{exchangeSymbol(row.minOperationSymbol)}
            销售单价
            {symbolMatch(row.maxOperationSymbol)}
            {row.maxValue}元
          </span>,
          <span v-show={+row.sectionType === 2}>
            销售单价
            {symbolMatch(row.minOperationSymbol)}
            {row.minValue}元
          </span>
        ]
      }
    },
    {
      label: '业务提成',
      render: (h, row) => {
        return [<span>{row.proportion} %</span>]
      }
    },
    {
      label: '业务提成',
      hide: !ctx.isNotPointCard,
      render: (h, row) => {
        return [<span>{row.proportion} %</span>]
      }
    },
    {
      label: '操作',
      render: (h, row, index) => {
        const len = ctx.form.proportionData.length
        const isDisabled = index !== (len - 1) && index !== 0
        return [
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.configOperation('edit', row, index)
            }}
          >
            编辑
          </el-link>,
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            disabled={isDisabled}
            onClick={() => {
              ctx.configOperation('del', row, index)
            }}
          >
            删除
          </el-link>
        ]
      }
    }
  ]
}
// 有效期规则
export const expiredColumns = ctx => {
  return [
    {
      label: '档位',
      render: (h, row, index) => {
        return <span>档位 {index + 1}</span>
      }
    },
    {
      label: '销售数量',
      render: (h, row) => {
        return [
          <span v-show={+row.sectionType === 1}>
            {row.minValue}张{exchangeSymbol(row.minOperationSymbol)}
            销售数量
            {symbolMatch(row.maxOperationSymbol)}
            {row.maxValue}张
          </span>,
          <span v-show={+row.sectionType === 2}>
            销售数量
            {symbolMatch(row.minOperationSymbol)}
            {row.minValue}张
          </span>
        ]
      }
    },
    {
      prop: 'day',
      label: '有效期天数'
    },
    {
      label: '操作',
      render: (h, row, index) => {
        const len = ctx.form.expiredData.length
        const isDisabled = index !== (len - 1) && index !== 0
        return [
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.expiredOperation('edit', row, index)
            }}
          >
            编辑
          </el-link>,
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            disabled={isDisabled}
            onClick={() => {
              ctx.expiredOperation('del', row, index)
            }}
          >
            删除
          </el-link>
        ]
      }
    }
  ]
}
// 点卡-电影提成配置
export const movieColumns = ctx => {
  return [
    {
      label: '档位',
      render: (h, row, index) => {
        return <span>档位 {index + 1}</span>
      }
    },
    {
      label: '销售折扣(%)',
      render: (h, row) => {
        return [<span>{row.minValue} %</span>]
      }
    },
    {
      label: '固定提成(%)',
      render: (h, row) => {
        return [<span>{row.proportion} %</span>]
      }
    },
    {
      label: '操作',
      render: (h, row, index) => {
        const len = ctx.form.proportionData.length
        const isDisabled = index !== (len - 1) && index !== 0
        return [
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.onPointCardSetConfig('edit', row, index)
            }}
          >
            编辑
          </el-link>,
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.configOperation('del', row, index)
            }}
          >
            删除
          </el-link>
        ]
      }
    }
  ]
}
// 点卡-心选提成配置
export const heartColumns = ctx => {
  return [
    {
      label: '档位',
      render: (h, row, index) => {
        return <span>档位 {index + 1}</span>
      }
    },
    {
      label: '销售折扣',
      render: (h, row) => {
        return [
          <span v-show={+row.sectionType === 1}>
            {row.minValue}%{exchangeSymbol(row.minOperationSymbol)}
            销售折扣
            {symbolMatch(row.maxOperationSymbol)}
            {row.maxValue}%
          </span>,
          <span v-show={+row.sectionType === 2}>
            销售折扣
            {symbolMatch(row.minOperationSymbol)}
            {row.minValue}%
          </span>
        ]
      }
    },
    {
      label: '业务提成',
      render: (h, row) => {
        return [<span>{row.proportion} %</span>]
      }
    },
    {
      label: '操作',
      render: (h, row, index) => {
        const len = ctx.form.proportionData.length
        const isDisabled = index !== (len - 1) && index !== 0
        return [
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.onPointCardSetConfig('edit', row, index)
            }}
          >
            编辑
          </el-link>,
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.configOperation('del', row, index)
            }}
            disabled={isDisabled}
          >
            删除
          </el-link>
        ]
      }
    }
  ]
}
// 次卡-提成方案
export const secondCardColumns = ctx => {
  return [
    {
      prop: 'productCode',
      label: '产品编码'
    },
    {
      prop: 'businessTypeName',
      label: '业务类型'
    },
    {
      prop: 'name',
      label: '商品名称'
    },
    {
      prop: 'typeName',
      label: '产品类型'
    },
    {
      prop: 'parValue',
      label: '产品面值'
    },
    {
      prop: 'apartmentName',
      label: '可销售部门'
    },
    {
      label: '最低销售数量(张)',
      width: 240,
      render: (h, row, index) => {
        let item = ctx.form.proportionTimesData.filter(i => { return i.couponProductId === row.id })[0]
        return [
          <el-input
            placeholder="请输入内容"
            value={item.minSaleNumber}
            onInput={val => {
              item.minSaleNumber = val
            }}
            type="number"
            class="input-with-select"
          >
            <el-select
              class="w80"
              value={item.minSaleNumberOperationSymbol}
              onInput={val => {
                item.minSaleNumberOperationSymbol = val
              }}
              slot="prepend"
              placeholder="请选择"
            >
              <el-option label="大于" value="1" />
              <el-option label="大于等于" value="2" />
            </el-select>
          </el-input>
        ]
      }
    },
    {
      label: '单张卡含券张数(张)',
      width: 240,
      render: (h, row, index) => {
        let item = ctx.form.proportionTimesData.filter(i => { return i.couponProductId === row.id })[0]
        return [
          <el-input
            placeholder="请输入内容"
            value={item.couponNumber}
            onInput={val => {
              item.couponNumber = val
            }}
            type="number"
            class="input-with-select"
          >
            <el-select
              class="w80"
              value={item.couponNumberOperationSymbol}
              onInput={val => {
                item.couponNumberOperationSymbol = val
              }}
              slot="prepend"
              placeholder="请选择"
            >
              <el-option label="大于" value="1" />
              <el-option label="大于等于" value="2" />
            </el-select>
          </el-input>
        ]
      }
    },
    {
      label: '操作',
      fixed: 'right',
      render: (h, row, index) => {
        return [
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.secondOperation('detail', row, index)
            }}
          >
            详情
          </el-link>,
          <el-link
            underline={false}
            type="primary"
            class="mr10"
            onClick={() => {
              ctx.secondOperation('del', row, index)
            }}
          >
            删除
          </el-link>
        ]
      }
    }
  ]
}

export const practiceCostPriceTypeList = [
  {
    value: '1',
    label: '区间范围设置'
  },
  {
    value: '2',
    label: '固定值设置'
  }
]
